package com.koi.classservice;

import com.alibaba.excel.EasyExcel;
import com.koi.classservice.Utils.CourseDataReverseParser;
import com.koi.classservice.domain.po.Course;
import com.koi.classservice.domain.po.CourseTest;
import com.koi.classservice.handler.CourseExcelListener;
import com.koi.classservice.service.ICourseScheduleService;
import com.koi.classservice.service.IReverseCourseScheduleService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@SpringBootTest
public class inserttest {

    @Autowired
    private ICourseScheduleService courseSchedulese;
    @Autowired
    private IReverseCourseScheduleService reverseCourseScheduleService;

//    @Test
//    public void run()  {
//        String filePath = "src/main/resources/xlxFilm/课表.xls";
//        CourseExcelListener listener = new CourseExcelListener();
//        EasyExcel.read(filePath, Course.class, listener).sheet().doRead();
//        List<Course> courses = listener.getCourses();
//
//        List<CourseSchedule> scheduleList = DataParser.parseCourses(courses);
//
//        //输出
//        for (CourseSchedule schedule : scheduleList) {
//            System.out.println(schedule);
//        }
//
//
////        for (CourseSchedule schedule : scheduleList) {
////            courseSchedulese.save(schedule);
////        }
//    }


    @Test
    public void run() {
        String filePath = "src/main/resources/xlxFilm/课表.xls";
        CourseExcelListener listener = new CourseExcelListener();
        EasyExcel.read(filePath, Course.class, listener).sheet().doRead();
        List<Course> courses = listener.getCourses();

        //List<ReverseCourseSchedule> scheduleList = CourseDataReverseParser.parseCourses(courses);

//        for (ReverseCourseSchedule schedule : scheduleList) {
//            System.out.println(schedule);
//        }

//        for (ReverseCourseSchedule schedule : scheduleList) {
//            reverseCourseScheduleService.save(schedule);
//        }


        // 批量插入数据
//        if (!scheduleList.isEmpty()) {
//            reverseCourseScheduleMapper.insertBatch(scheduleList);
//        }
    }


    @Test
    public void run2() {
        String filePath = "D:\\MyClub\\MyClub\\class-service\\src\\main\\resources\\xlxFilm\\课表.xls";
        CourseExcelListener listener = new CourseExcelListener();
        EasyExcel.read(filePath, Course.class, listener).sheet().doRead();
        List<Course> courses = listener.getCourses();

        int target=8;
        String jie="五[7-8节]";

        HashMap<String, List<String>> classmap = new HashMap<>();
        for (Course course : courses) {
            String classroom = course.getClassroom();
            String week = course.getWeek();
            String session = course.getSession();
            String list= week+","+session;
            if (classmap.containsKey(classroom)) {
                classmap.get(classroom).add(list);
            }
            else{
                List<String> list1 = new ArrayList<>();
                list1.add(list);
                classmap.put(classroom,list1);
            }
        }
        //拿到map里面的数据
        for (String classroom : classmap.keySet()) {
            List<String> list = classmap.get(classroom);
            List<Integer> tmp=new ArrayList<>();
            CourseTest test=new CourseTest();
            for (String s : list) {
                 test=CourseDataReverseParser.parseCourses(s);
                 if(test.getKeTime().contains(jie)){
                     int flag=0;
                     List<Integer> list1=test.getWeek();
                     for (Integer integer : list1) {
                         if(integer==target){
                             flag=1;
                             break;
                         }
                     }
                     if(flag==0){
                         System.out.println("第"+target+"周"+classroom+" "+ test.getKeTime()+"没课");
                     }
                     else{
                         System.out.println("第"+target+"周"+classroom+" "+ test.getKeTime()+"有课");
                     }

                 }
            }


        }



        //List<ReverseCourseSchedule> scheduleList = CourseDataReverseParser.parseCourses(courses);

//        for (ReverseCourseSchedule schedule : scheduleList) {
//            System.out.println(schedule);
//        }

//        for (ReverseCourseSchedule schedule : scheduleList) {
//            reverseCourseScheduleService.save(schedule);
//        }


        // 批量插入数据
//        if (!scheduleList.isEmpty()) {
//            reverseCourseScheduleMapper.insertBatch(scheduleList);
//        }

    }




}
